//package com.feinno.urcs.group.pd.util;
//
//import com.feinno.cpim.CpimHeader;
//import com.feinno.cpim.CpimMessage;
//import com.feinno.cpim.ImdnNotificationXml;
//import com.feinno.sip.address.AddressImpl;
//import com.feinno.sip.address.SipUri;
//import com.feinno.sip.header.ContentType;
//import com.feinno.sip.header.extensions.ReferredBy;
//import com.feinno.sip.header.ims.PAssertedIdentity;
//import com.feinno.sip.message.Content;
//import com.feinno.sip.util.IDUtils;
//import com.feinno.threading.Future;
//import com.feinno.threading.FutureListener;
//import com.feinno.urcs.content.MimeType;
//import com.feinno.urcs.content.UrcsMultipartMimeContent;
//import com.feinno.urcs.group.siptask.task.GroupMessageArgs;
//import com.feinno.urcs.nai.IMPU;
//import com.feinno.urcs.sip.SipConnector;
//import com.feinno.urcs.sip.UrcsSipFactory;
//import com.feinno.urcs.sipservlet.ImMsgTechEnum;
//import com.feinno.urcs.sipservlet.uac2.RcsLargeModeUAC;
//import com.feinno.urcs.sipservlet.uac2.RcsPageModeUAC;
//import com.feinno.urcs.sipservlet.uac.RcsUACArgs;
//import com.feinno.util.Result;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//import java.text.ParseException;
//
//
///**
// * Created by wuhao on 5/11/15.
// */
//public class PdGroupMessageHelper {
//    /**
//     *  发送largemode类型消息
//     *  @author wuhao
//     */
//    public static void sendLargeMode(GroupMessageArgs groupMessageArgs){
//        final Logger LOGGER = LoggerFactory.getLogger(PdGroupMessageHelper.class);
//        LOGGER.info("PdGroupMessageHelper send  large mode method start");
//        CpimMessage cpimMessage = createCpimMessage(groupMessageArgs);
//        //构造SIP消息体
//        //pai
//        PAssertedIdentity pai = null;
//        // Add refer-by发送者的信息
//        ReferredBy referredBy = new ReferredBy();
//        try {
//            pai = new PAssertedIdentity(
//                    (AddressImpl) UrcsSipFactory.getAddressFactory().createAddress(
//                            groupMessageArgs.getFromMobile()
//                    )
//            );
//            referredBy.setAddress(UrcsSipFactory.getAddressFactory().createAddress(
//                    groupMessageArgs.getFromMobile()
//            ));
//        } catch (ParseException e) {
//            LOGGER.error("PdGroupMessageHelper createAddress Error: {}", e);
//        }
//        //sipConnector
//        SipConnector sipConnector = getSipConnector();
//        IMPU sender  = new IMPU();
//        IMPU recever = new IMPU();
//        sender.setUser(groupMessageArgs.getFromMobile());
//        recever.setUser(groupMessageArgs.getToMobile());
//        RcsUACArgs entity = new RcsUACArgs(pai, sender, recever, sipConnector,
//                getCscf(), sipConnector.getContact());
//        //ContentType
//        ContentType contentType = (ContentType) (MimeType.CPIM.getContentTypeHeader());
//        ImMsgTechEnum msgTech = null;
//        // TODO
//        //msgTech = NamingService.lookupEnum(ImMsgTechEnum.class, "im_msgtech");
//        final RcsLargeModeUAC uac = new RcsLargeModeUAC(msgTech, entity);
//        final UrcsMultipartMimeContent content =
//                UrcsMultipartMimeContent.newInstance(contentType, cpimMessage.getByteArray());
//        final Content sconData;
//        Future<Integer> future = uac.begin();
//        future.addListener(new FutureListener<Integer>() {
//            @Override
//            public void run(Result<Integer> result) {
//                try {
//                    if (result.getValue() != 200) {
//                        LOGGER.error("send page mode begin return {}.", result.getValue());
//                        uac.end();
//                        return;
//                    }
//                    Future<Integer> sendFuture = uac.send((Content) content);
//                    sendFuture.addListener(new FutureListener<Integer>() {
//                        @Override
//                        public void run(Result<Integer> result) {
//                            if (result.getValue() != 200) {
//                                LOGGER.error("send page mode send return {}.", result.getValue());
//                                uac.end();
//                                return;
//                            }
//                            if (LOGGER.isInfoEnabled()) {
//                                LOGGER.info("sendPageMode successfully:{}", new String(content.toByteArray()));
//                            }
//                            uac.end();
//                            return;
//                        }
//                    });
//                } catch (Exception e) {
//                    LOGGER.error("send page mode begin callback process error. {}", e);
//                }
//            }
//        });
//
//        LOGGER.info("PdGroupMessageHelper send large mode method end");
//    }
//    /**
//     *  发送pagemode类型消息
//     *  @author wuhao
//     */
//    public static void sendPageMode(GroupMessageArgs groupMessageArgs){
//        final Logger LOGGER = LoggerFactory.getLogger(PdGroupMessageHelper.class);
//        LOGGER.info("PdGroupMessageHelper send page mode method start");
//
//        //构造CPIM消息内容
//        CpimMessage cpimMessage = createCpimMessage(groupMessageArgs);
//
//        //构造SIP消息体
//        //pai
//        PAssertedIdentity pai = null;
//        // Add refer-by发送者的信息
//        ReferredBy referredBy = new ReferredBy();
//        try {
//            pai = new PAssertedIdentity(
//                    (AddressImpl) UrcsSipFactory.getAddressFactory().createAddress(
//                            groupMessageArgs.getFromMobile()
//                    )
//            );
//            referredBy.setAddress(UrcsSipFactory.getAddressFactory().createAddress(
//                    groupMessageArgs.getFromMobile()
//            ));
//        } catch (ParseException e) {
//            LOGGER.error("PdGroupMessageHelper createAddress Error: {}", e);
//        }
//        //sipConnector
//        SipConnector sipConnector = getSipConnector();
//        IMPU sender  = new IMPU();
//        IMPU recever = new IMPU();
//        sender.setUser(groupMessageArgs.getFromMobile());
//        recever.setUser(groupMessageArgs.getToMobile());
//        RcsUACArgs entity = new RcsUACArgs(pai, sender, recever, sipConnector,
//                getCscf(), sipConnector.getContact());
//        //ContentType
//        ContentType contentType = (ContentType) (MimeType.CPIM.getContentTypeHeader());
//        ImMsgTechEnum msgTech = null;
//        //??????????????????????????????????????
//        //msgTech = NamingService.lookupEnum(ImMsgTechEnum.class, "im_msgtech");
//        final RcsPageModeUAC uac = new RcsPageModeUAC(msgTech, entity);
//        final UrcsMultipartMimeContent content =
//                UrcsMultipartMimeContent.newInstance(contentType, cpimMessage.getByteArray());
//        Future<Integer> future = uac.begin();
//        future.addListener(new FutureListener<Integer>() {
//            @Override
//            public void run(Result<Integer> result) {
//                try {
//                    if (result.getValue() != 200) {
//                        LOGGER.error("send page mode begin return {}.", result.getValue());
//                        uac.end();
//                        return;
//                    }
//                    Future<Integer> sendFuture = uac.send(content);
//                    sendFuture.addListener(new FutureListener<Integer>() {
//                        @Override
//                        public void run(Result<Integer> result) {
//                            if (result.getValue() != 200) {
//                                LOGGER.error("send page mode send return {}.", result.getValue());
//                                uac.end();
//                                return;
//                            }
//                            if (LOGGER.isInfoEnabled()) {
//                                LOGGER.info("sendPageMode successfully:{}", new String(content.toByteArray()));
//                            }
//                            uac.end();
//                            return;
//                        }
//                    });
//                } catch (Exception e) {
//                    LOGGER.error("send page mode begin callback process error. {}", e);
//                }
//            }
//        });
//        if (LOGGER.isInfoEnabled()) {
//            LOGGER.info("sendPageMode:{}", new String(content.toByteArray()));
//        }
//        LOGGER.info("PdGroupMessageHelper send page mode method end");
//    }
//    /***
//     * 获取SipConnector
//     *
//     * @author wuhao
//     */
//    public static CpimMessage createCpimMessage(GroupMessageArgs groupMessageArgs){
//        CpimMessage cpimMessage = new CpimMessage();
//        cpimMessage.setContentByteArray(groupMessageArgs.getContent());
//        cpimMessage.addHeader(new CpimHeader(CpimHeader.FROM, String.format("<%s>", groupMessageArgs.getToMobile())));
//        cpimMessage.addHeader(new CpimHeader(CpimHeader.TO, String.format("<%s>", groupMessageArgs.getToMobile())));
//        cpimMessage.addHeader(new CpimHeader(CpimHeader.NS, "imdn<urn:ietf:params:imdn>"));
//        cpimMessage.addHeader(new CpimHeader(CpimHeader.MESSAGE_ID, IDUtils.createId(8)));
//        cpimMessage.addHeader(new CpimHeader(CpimHeader.DATETIME, ImdnNotificationXml.getUTCTimeNow()));
//        cpimMessage.addHeader(new CpimHeader(CpimHeader.Disposition_Notification, "positive-delivery, display"));
//        cpimMessage.addHeader(new CpimHeader(CpimHeader.CONTENT_TYPE, "text/plain"));
//        cpimMessage.addHeader(new CpimHeader(CpimHeader.CONTENT_LENGTH, String.valueOf(groupMessageArgs.getContent().length)));
//        cpimMessage.addHeader(new CpimHeader("Content-Transfer-Encoding", "base64"));
//        return cpimMessage;
//    }
//
//    /***
//     * 获取SipConnector
//     *
//     * @author wuhao
//     */
//    public static SipConnector getSipConnector() {
//        return null;
//    }
//
//    /***
//     * 获取CSCF
//     *
//     * @author wuhao
//     */
//    public static SipUri getCscf() {
//        SipUri sipUri = null;
//        return sipUri;
//    }
//
//    /***
//     * 获取pagemode最大支持数
//     *
//     * @author wuhao
//     */
//    public static int getPageModeMaxSize() {
//        int pageModeMaxSize = 900;
//        return pageModeMaxSize;
//    }
//}
